package com.itheima;

import org.springframework.amqp.core.*;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class RabbitmqDemo01Application {
    public static void main(String[] args) {
        SpringApplication.run(RabbitmqDemo01Application.class,args);
    }

    //创建正常交换机
    @Bean
    public DirectExchange creatExchange(){
        return new DirectExchange("exchange_direct_demo01");
    }
    //创建正常队列
    @Bean
    public Queue createQueue(){
        return QueueBuilder.durable("queue_demo01")
                .withArgument("x-dead-letter-exchange","exchange_die_order")//设置死信交换机
                .withArgument("x-dead-letter-routing-key","item.order")//设置死信路由key
                .build();
    }

    //创建正常绑定
    @Bean
    public Binding createBinding(){
        return BindingBuilder.bind(createQueue()).to(creatExchange()).with("item.insert");
    }





    //创建死信交换机
    @Bean
    public DirectExchange createDieExchange(){
        return new DirectExchange("exchange_die_order");
    }

    //创建死信队列
    @Bean
    public Queue createDieQueue(){
        return QueueBuilder
                .durable("queue_die_order").build();

    }

    //创建死信绑定 将正常队列绑定到死信交换机上
    @Bean
    public Binding createBindingDelay(){
        return BindingBuilder.bind(createDieQueue()).to(createDieExchange()).with("item.order");
    }
}
